package com.ncst.mvcweb.service.impl;

import com.ncst.mvcweb.dao.UserDao;
import com.ncst.mvcweb.entity.User;
import com.ncst.mvcweb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findByUsernameAndPassword(String username, String password) {
        return userDao.findByUsernameAndPassword(username, password);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public void delete(Integer id) {
        userDao.deleteById(id);
    }

    @Override
    public void delete(List<Integer> idList) {
        for (Integer id : idList)
            userDao.deleteById(id);
    }

    @Override
    public User queryById(Integer id) {
        return userDao.findById(id).orElse(null);
    }

    @Override
    public User save(User user) {
        return userDao.save(user);
    }

    @Override
    public User findByUsername(String username) {
        return userDao.findByUsername(username);
    }

    @Override
    public void updateById(User user) {
        userDao.save(user);
    }
}


